/*
 * @Description: 添加、编辑cd表单
 * @Author: Rfan
 * @Date: 2022-06-25 17:18:37
 * @LastEditTime: 2022-06-27 16:03:28
 */
import { Form, Input, InputNumber, Radio, Select, Space } from 'antd';
import { unitList } from '../index';

const { Option } = Select;

const CDForm = () => {
  return (
    <>
      <Form.Item
        name="diskName"
        label="光盘名称"
        rules={[{ required: true, message: '请选择模板' }]}
      >
        <Input />
      </Form.Item>
      <Form.Item name="volumeType" label="光盘容量">
        <Radio.Group>
          <Space direction="vertical">
            <Space>
              <Radio value={0}>自定义</Radio>
              <Form.Item
                noStyle
                shouldUpdate={(prevValues, curValues) =>
                  prevValues.volumeType !== curValues.volumeType
                }
              >
                {({ getFieldValue }) => {
                  return (
                    <Form.Item
                      name={getFieldValue('volumeType') === 1 ? undefined : 'diskVolume'}
                      noStyle
                    >
                      <InputNumber disabled={getFieldValue('volumeType') === 1} />
                    </Form.Item>
                  );
                }}
              </Form.Item>
              <Form.Item
                noStyle
                shouldUpdate={(prevValues, curValues) =>
                  prevValues.volumeType !== curValues.volumeType
                }
              >
                {({ getFieldValue }) => {
                  return (
                    <Form.Item
                      name={getFieldValue('volumeType') === 1 ? undefined : 'volumeUnit'}
                      noStyle
                    >
                      <Select disabled={getFieldValue('volumeType') === 1} style={{ width: 80 }}>
                        {unitList.map((unit) => (
                          <Option key={unit.value} value={unit.value}>
                            {unit.name}
                          </Option>
                        ))}
                      </Select>
                    </Form.Item>
                  );
                }}
              </Form.Item>
            </Space>
            <Radio value={1}>不限制</Radio>
          </Space>
        </Radio.Group>
      </Form.Item>
    </>
  );
};

export default CDForm;
